# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
# RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx908 -run-pass=si-fold-operands -verify-machineinstrs -o - %s | FileCheck --check-prefix=GFX908 %s
# RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx90a -run-pass=si-fold-operands -verify-machineinstrs -o - %s | FileCheck --check-prefix=GFX90A %s

# Should fold all copies for gfx908. In case of gfx90a, the folding must happen only for the aligned cases.

---
name:            aligned_vgpr_64
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $vgpr0_vgpr1
    ; GFX908-LABEL: name: aligned_vgpr_64
    ; GFX908: liveins: $vgpr0_vgpr1
    ; GFX908-NEXT: {{  $}}
    ; GFX908-NEXT: [[COPY:%[0-9]+]]:vreg_64_align2 = COPY $vgpr0_vgpr1
    ; GFX908-NEXT: [[DEF:%[0-9]+]]:vreg_64_align2 = IMPLICIT_DEF
    ; GFX908-NEXT: GLOBAL_STORE_DWORDX2 [[COPY]], [[DEF]], 0, 0, implicit $exec
    ; GFX90A-LABEL: name: aligned_vgpr_64
    ; GFX90A: liveins: $vgpr0_vgpr1
    ; GFX90A-NEXT: {{  $}}
    ; GFX90A-NEXT: [[COPY:%[0-9]+]]:vreg_64_align2 = COPY $vgpr0_vgpr1
    ; GFX90A-NEXT: [[DEF:%[0-9]+]]:vreg_64_align2 = IMPLICIT_DEF
    ; GFX90A-NEXT: GLOBAL_STORE_DWORDX2 [[COPY]], [[DEF]], 0, 0, implicit $exec
    %0:vreg_64_align2 = COPY $vgpr0_vgpr1
    %1:vreg_64_align2 = IMPLICIT_DEF
    %2:vreg_64_align2 = COPY killed %1
    GLOBAL_STORE_DWORDX2 %0, %2, 0, 0, implicit $exec
...

---
name:            unaligned_vgpr_64
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $vgpr0_vgpr1
    ; GFX908-LABEL: name: unaligned_vgpr_64
    ; GFX908: liveins: $vgpr0_vgpr1
    ; GFX908-NEXT: {{  $}}
    ; GFX908-NEXT: [[COPY:%[0-9]+]]:vreg_64_align2 = COPY $vgpr0_vgpr1
    ; GFX908-NEXT: [[DEF:%[0-9]+]]:vreg_64 = IMPLICIT_DEF
    ; GFX908-NEXT: GLOBAL_STORE_DWORDX2 [[COPY]], [[DEF]], 0, 0, implicit $exec
    ; GFX90A-LABEL: name: unaligned_vgpr_64
    ; GFX90A: liveins: $vgpr0_vgpr1
    ; GFX90A-NEXT: {{  $}}
    ; GFX90A-NEXT: [[COPY:%[0-9]+]]:vreg_64_align2 = COPY $vgpr0_vgpr1
    ; GFX90A-NEXT: [[DEF:%[0-9]+]]:vreg_64 = IMPLICIT_DEF
    ; GFX90A-NEXT: [[COPY1:%[0-9]+]]:vreg_64_align2 = COPY killed [[DEF]]
    ; GFX90A-NEXT: GLOBAL_STORE_DWORDX2 [[COPY]], [[COPY1]], 0, 0, implicit $exec
    %0:vreg_64_align2 = COPY $vgpr0_vgpr1
    %1:vreg_64 = IMPLICIT_DEF
    %2:vreg_64_align2 = COPY killed %1
    GLOBAL_STORE_DWORDX2 %0, %2, 0, 0, implicit $exec
...

---
name:            aligned_vgpr_96_sub0_subg1
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $vgpr0_vgpr1
    ; GFX908-LABEL: name: aligned_vgpr_96_sub0_subg1
    ; GFX908: liveins: $vgpr0_vgpr1
    ; GFX908-NEXT: {{  $}}
    ; GFX908-NEXT: [[COPY:%[0-9]+]]:vreg_64_align2 = COPY $vgpr0_vgpr1
    ; GFX908-NEXT: [[DEF:%[0-9]+]]:vreg_96_align2 = IMPLICIT_DEF
    ; GFX908-NEXT: GLOBAL_STORE_DWORDX2 [[COPY]], [[DEF]].sub0_sub1, 0, 0, implicit $exec
    ; GFX90A-LABEL: name: aligned_vgpr_96_sub0_subg1
    ; GFX90A: liveins: $vgpr0_vgpr1
    ; GFX90A-NEXT: {{  $}}
    ; GFX90A-NEXT: [[COPY:%[0-9]+]]:vreg_64_align2 = COPY $vgpr0_vgpr1
    ; GFX90A-NEXT: [[DEF:%[0-9]+]]:vreg_96_align2 = IMPLICIT_DEF
    ; GFX90A-NEXT: GLOBAL_STORE_DWORDX2 [[COPY]], [[DEF]].sub0_sub1, 0, 0, implicit $exec
    %0:vreg_64_align2 = COPY $vgpr0_vgpr1
    %1:vreg_96_align2 = IMPLICIT_DEF
    %2:vreg_64_align2 = COPY killed %1.sub0_sub1:vreg_96_align2
    GLOBAL_STORE_DWORDX2 %0, %2, 0, 0, implicit $exec
...

---
name:            unaligned_vgpr_96_sub1_sub2
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $vgpr0_vgpr1
    ; GFX908-LABEL: name: unaligned_vgpr_96_sub1_sub2
    ; GFX908: liveins: $vgpr0_vgpr1
    ; GFX908-NEXT: {{  $}}
    ; GFX908-NEXT: [[COPY:%[0-9]+]]:vreg_64_align2 = COPY $vgpr0_vgpr1
    ; GFX908-NEXT: [[DEF:%[0-9]+]]:vreg_96_align2 = IMPLICIT_DEF
    ; GFX908-NEXT: GLOBAL_STORE_DWORDX2 [[COPY]], [[DEF]].sub1_sub2, 0, 0, implicit $exec
    ; GFX90A-LABEL: name: unaligned_vgpr_96_sub1_sub2
    ; GFX90A: liveins: $vgpr0_vgpr1
    ; GFX90A-NEXT: {{  $}}
    ; GFX90A-NEXT: [[COPY:%[0-9]+]]:vreg_64_align2 = COPY $vgpr0_vgpr1
    ; GFX90A-NEXT: [[DEF:%[0-9]+]]:vreg_96_align2 = IMPLICIT_DEF
    ; GFX90A-NEXT: [[COPY1:%[0-9]+]]:vreg_64_align2 = COPY killed [[DEF]].sub1_sub2
    ; GFX90A-NEXT: GLOBAL_STORE_DWORDX2 [[COPY]], [[COPY1]], 0, 0, implicit $exec
    %0:vreg_64_align2 = COPY $vgpr0_vgpr1
    %1:vreg_96_align2 = IMPLICIT_DEF
    %2:vreg_64_align2 = COPY killed %1.sub1_sub2:vreg_96_align2
    GLOBAL_STORE_DWORDX2 %0, %2, 0, 0, implicit $exec
...

---
name:            aligned_vgpr_96
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $vgpr0_vgpr1
    ; GFX908-LABEL: name: aligned_vgpr_96
    ; GFX908: liveins: $vgpr0_vgpr1
    ; GFX908-NEXT: {{  $}}
    ; GFX908-NEXT: [[COPY:%[0-9]+]]:vreg_64_align2 = COPY $vgpr0_vgpr1
    ; GFX908-NEXT: [[DEF:%[0-9]+]]:vreg_96_align2 = IMPLICIT_DEF
    ; GFX908-NEXT: GLOBAL_STORE_DWORDX3 [[COPY]], [[DEF]], 0, 0, implicit $exec
    ; GFX90A-LABEL: name: aligned_vgpr_96
    ; GFX90A: liveins: $vgpr0_vgpr1
    ; GFX90A-NEXT: {{  $}}
    ; GFX90A-NEXT: [[COPY:%[0-9]+]]:vreg_64_align2 = COPY $vgpr0_vgpr1
    ; GFX90A-NEXT: [[DEF:%[0-9]+]]:vreg_96_align2 = IMPLICIT_DEF
    ; GFX90A-NEXT: GLOBAL_STORE_DWORDX3 [[COPY]], [[DEF]], 0, 0, implicit $exec
    %0:vreg_64_align2 = COPY $vgpr0_vgpr1
    %1:vreg_96_align2 = IMPLICIT_DEF
    %2:vreg_96_align2 = COPY killed %1
    GLOBAL_STORE_DWORDX3 %0, %2, 0, 0, implicit $exec
...

---
name:            unaligned_vgpr_96
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $vgpr0_vgpr1
    ; GFX908-LABEL: name: unaligned_vgpr_96
    ; GFX908: liveins: $vgpr0_vgpr1
    ; GFX908-NEXT: {{  $}}
    ; GFX908-NEXT: [[COPY:%[0-9]+]]:vreg_64_align2 = COPY $vgpr0_vgpr1
    ; GFX908-NEXT: [[DEF:%[0-9]+]]:vreg_96 = IMPLICIT_DEF
    ; GFX908-NEXT: GLOBAL_STORE_DWORDX3 [[COPY]], [[DEF]], 0, 0, implicit $exec
    ; GFX90A-LABEL: name: unaligned_vgpr_96
    ; GFX90A: liveins: $vgpr0_vgpr1
    ; GFX90A-NEXT: {{  $}}
    ; GFX90A-NEXT: [[COPY:%[0-9]+]]:vreg_64_align2 = COPY $vgpr0_vgpr1
    ; GFX90A-NEXT: [[DEF:%[0-9]+]]:vreg_96 = IMPLICIT_DEF
    ; GFX90A-NEXT: [[COPY1:%[0-9]+]]:vreg_96_align2 = COPY killed [[DEF]]
    ; GFX90A-NEXT: GLOBAL_STORE_DWORDX3 [[COPY]], [[COPY1]], 0, 0, implicit $exec
    %0:vreg_64_align2 = COPY $vgpr0_vgpr1
    %1:vreg_96 = IMPLICIT_DEF
    %2:vreg_96_align2 = COPY killed %1
    GLOBAL_STORE_DWORDX3 %0, %2, 0, 0, implicit $exec
...

---
name:            aligned_vgpr_128_sub0_sub1
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $vgpr0_vgpr1
    ; GFX908-LABEL: name: aligned_vgpr_128_sub0_sub1
    ; GFX908: liveins: $vgpr0_vgpr1
    ; GFX908-NEXT: {{  $}}
    ; GFX908-NEXT: [[COPY:%[0-9]+]]:vreg_64_align2 = COPY $vgpr0_vgpr1
    ; GFX908-NEXT: [[DEF:%[0-9]+]]:vreg_128_align2 = IMPLICIT_DEF
    ; GFX908-NEXT: GLOBAL_STORE_DWORDX2 [[COPY]], [[DEF]].sub0_sub1, 0, 0, implicit $exec
    ; GFX90A-LABEL: name: aligned_vgpr_128_sub0_sub1
    ; GFX90A: liveins: $vgpr0_vgpr1
    ; GFX90A-NEXT: {{  $}}
    ; GFX90A-NEXT: [[COPY:%[0-9]+]]:vreg_64_align2 = COPY $vgpr0_vgpr1
    ; GFX90A-NEXT: [[DEF:%[0-9]+]]:vreg_128_align2 = IMPLICIT_DEF
    ; GFX90A-NEXT: GLOBAL_STORE_DWORDX2 [[COPY]], [[DEF]].sub0_sub1, 0, 0, implicit $exec
    %0:vreg_64_align2 = COPY $vgpr0_vgpr1
    %1:vreg_128_align2 = IMPLICIT_DEF
    %2:vreg_64_align2 = COPY killed %1.sub0_sub1:vreg_128_align2
    GLOBAL_STORE_DWORDX2 %0, %2, 0, 0, implicit $exec
...

---
name:            aligned_vgpr_128_sub2_sub3
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $vgpr0_vgpr1
    ; GFX908-LABEL: name: aligned_vgpr_128_sub2_sub3
    ; GFX908: liveins: $vgpr0_vgpr1
    ; GFX908-NEXT: {{  $}}
    ; GFX908-NEXT: [[COPY:%[0-9]+]]:vreg_64_align2 = COPY $vgpr0_vgpr1
    ; GFX908-NEXT: [[DEF:%[0-9]+]]:vreg_128_align2 = IMPLICIT_DEF
    ; GFX908-NEXT: GLOBAL_STORE_DWORDX2 [[COPY]], [[DEF]].sub2_sub3, 0, 0, implicit $exec
    ; GFX90A-LABEL: name: aligned_vgpr_128_sub2_sub3
    ; GFX90A: liveins: $vgpr0_vgpr1
    ; GFX90A-NEXT: {{  $}}
    ; GFX90A-NEXT: [[COPY:%[0-9]+]]:vreg_64_align2 = COPY $vgpr0_vgpr1
    ; GFX90A-NEXT: [[DEF:%[0-9]+]]:vreg_128_align2 = IMPLICIT_DEF
    ; GFX90A-NEXT: GLOBAL_STORE_DWORDX2 [[COPY]], [[DEF]].sub2_sub3, 0, 0, implicit $exec
    %0:vreg_64_align2 = COPY $vgpr0_vgpr1
    %1:vreg_128_align2 = IMPLICIT_DEF
    %2:vreg_64_align2 = COPY killed %1.sub2_sub3:vreg_128_align2
    GLOBAL_STORE_DWORDX2 %0, %2, 0, 0, implicit $exec
...

---
name:            unaligned_vgpr_128_sub1_sub2
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $vgpr0_vgpr1
    ; GFX908-LABEL: name: unaligned_vgpr_128_sub1_sub2
    ; GFX908: liveins: $vgpr0_vgpr1
    ; GFX908-NEXT: {{  $}}
    ; GFX908-NEXT: [[COPY:%[0-9]+]]:vreg_64_align2 = COPY $vgpr0_vgpr1
    ; GFX908-NEXT: [[DEF:%[0-9]+]]:vreg_128_align2 = IMPLICIT_DEF
    ; GFX908-NEXT: GLOBAL_STORE_DWORDX2 [[COPY]], [[DEF]].sub1_sub2, 0, 0, implicit $exec
    ; GFX90A-LABEL: name: unaligned_vgpr_128_sub1_sub2
    ; GFX90A: liveins: $vgpr0_vgpr1
    ; GFX90A-NEXT: {{  $}}
    ; GFX90A-NEXT: [[COPY:%[0-9]+]]:vreg_64_align2 = COPY $vgpr0_vgpr1
    ; GFX90A-NEXT: [[DEF:%[0-9]+]]:vreg_128_align2 = IMPLICIT_DEF
    ; GFX90A-NEXT: [[COPY1:%[0-9]+]]:vreg_64_align2 = COPY killed [[DEF]].sub1_sub2
    ; GFX90A-NEXT: GLOBAL_STORE_DWORDX2 [[COPY]], [[COPY1]], 0, 0, implicit $exec
    %0:vreg_64_align2 = COPY $vgpr0_vgpr1
    %1:vreg_128_align2 = IMPLICIT_DEF
    %2:vreg_64_align2 = COPY killed %1.sub1_sub2:vreg_128_align2
    GLOBAL_STORE_DWORDX2 %0, %2, 0, 0, implicit $exec
...

---
name:            aligned_vgpr_128_sub0_sub1_sub2
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $vgpr0_vgpr1
    ; GFX908-LABEL: name: aligned_vgpr_128_sub0_sub1_sub2
    ; GFX908: liveins: $vgpr0_vgpr1
    ; GFX908-NEXT: {{  $}}
    ; GFX908-NEXT: [[COPY:%[0-9]+]]:vreg_64_align2 = COPY $vgpr0_vgpr1
    ; GFX908-NEXT: [[DEF:%[0-9]+]]:vreg_128_align2 = IMPLICIT_DEF
    ; GFX908-NEXT: GLOBAL_STORE_DWORDX3 [[COPY]], [[DEF]].sub0_sub1_sub2, 0, 0, implicit $exec
    ; GFX90A-LABEL: name: aligned_vgpr_128_sub0_sub1_sub2
    ; GFX90A: liveins: $vgpr0_vgpr1
    ; GFX90A-NEXT: {{  $}}
    ; GFX90A-NEXT: [[COPY:%[0-9]+]]:vreg_64_align2 = COPY $vgpr0_vgpr1
    ; GFX90A-NEXT: [[DEF:%[0-9]+]]:vreg_128_align2 = IMPLICIT_DEF
    ; GFX90A-NEXT: GLOBAL_STORE_DWORDX3 [[COPY]], [[DEF]].sub0_sub1_sub2, 0, 0, implicit $exec
    %0:vreg_64_align2 = COPY $vgpr0_vgpr1
    %1:vreg_128_align2 = IMPLICIT_DEF
    %2:vreg_96_align2 = COPY killed %1.sub0_sub1_sub2:vreg_128_align2
    GLOBAL_STORE_DWORDX3 %0, %2, 0, 0, implicit $exec
...

---
name:            unaligned_vgpr_128_sub1_sub2_sub3
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $vgpr0_vgpr1
    ; GFX908-LABEL: name: unaligned_vgpr_128_sub1_sub2_sub3
    ; GFX908: liveins: $vgpr0_vgpr1
    ; GFX908-NEXT: {{  $}}
    ; GFX908-NEXT: [[COPY:%[0-9]+]]:vreg_64_align2 = COPY $vgpr0_vgpr1
    ; GFX908-NEXT: [[DEF:%[0-9]+]]:vreg_128_align2 = IMPLICIT_DEF
    ; GFX908-NEXT: GLOBAL_STORE_DWORDX3 [[COPY]], [[DEF]].sub1_sub2_sub3, 0, 0, implicit $exec
    ; GFX90A-LABEL: name: unaligned_vgpr_128_sub1_sub2_sub3
    ; GFX90A: liveins: $vgpr0_vgpr1
    ; GFX90A-NEXT: {{  $}}
    ; GFX90A-NEXT: [[COPY:%[0-9]+]]:vreg_64_align2 = COPY $vgpr0_vgpr1
    ; GFX90A-NEXT: [[DEF:%[0-9]+]]:vreg_128_align2 = IMPLICIT_DEF
    ; GFX90A-NEXT: [[COPY1:%[0-9]+]]:vreg_96_align2 = COPY killed [[DEF]].sub1_sub2_sub3
    ; GFX90A-NEXT: GLOBAL_STORE_DWORDX3 [[COPY]], [[COPY1]], 0, 0, implicit $exec
    %0:vreg_64_align2 = COPY $vgpr0_vgpr1
    %1:vreg_128_align2 = IMPLICIT_DEF
    %2:vreg_96_align2 = COPY killed %1.sub1_sub2_sub3:vreg_128_align2
    GLOBAL_STORE_DWORDX3 %0, %2, 0, 0, implicit $exec
...

---
name:            aligned_vgpr_128
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $vgpr0_vgpr1
    ; GFX908-LABEL: name: aligned_vgpr_128
    ; GFX908: liveins: $vgpr0_vgpr1
    ; GFX908-NEXT: {{  $}}
    ; GFX908-NEXT: [[COPY:%[0-9]+]]:vreg_64_align2 = COPY $vgpr0_vgpr1
    ; GFX908-NEXT: [[DEF:%[0-9]+]]:vreg_128_align2 = IMPLICIT_DEF
    ; GFX908-NEXT: GLOBAL_STORE_DWORDX4 [[COPY]], [[DEF]], 0, 0, implicit $exec
    ; GFX90A-LABEL: name: aligned_vgpr_128
    ; GFX90A: liveins: $vgpr0_vgpr1
    ; GFX90A-NEXT: {{  $}}
    ; GFX90A-NEXT: [[COPY:%[0-9]+]]:vreg_64_align2 = COPY $vgpr0_vgpr1
    ; GFX90A-NEXT: [[DEF:%[0-9]+]]:vreg_128_align2 = IMPLICIT_DEF
    ; GFX90A-NEXT: GLOBAL_STORE_DWORDX4 [[COPY]], [[DEF]], 0, 0, implicit $exec
    %0:vreg_64_align2 = COPY $vgpr0_vgpr1
    %1:vreg_128_align2 = IMPLICIT_DEF
    %2:vreg_128_align2 = COPY killed %1
    GLOBAL_STORE_DWORDX4 %0, %2, 0, 0, implicit $exec
...

---
name:            unaligned_vgpr_128
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $vgpr0_vgpr1
    ; GFX908-LABEL: name: unaligned_vgpr_128
    ; GFX908: liveins: $vgpr0_vgpr1
    ; GFX908-NEXT: {{  $}}
    ; GFX908-NEXT: [[COPY:%[0-9]+]]:vreg_64_align2 = COPY $vgpr0_vgpr1
    ; GFX908-NEXT: [[DEF:%[0-9]+]]:vreg_128 = IMPLICIT_DEF
    ; GFX908-NEXT: GLOBAL_STORE_DWORDX4 [[COPY]], [[DEF]], 0, 0, implicit $exec
    ; GFX90A-LABEL: name: unaligned_vgpr_128
    ; GFX90A: liveins: $vgpr0_vgpr1
    ; GFX90A-NEXT: {{  $}}
    ; GFX90A-NEXT: [[COPY:%[0-9]+]]:vreg_64_align2 = COPY $vgpr0_vgpr1
    ; GFX90A-NEXT: [[DEF:%[0-9]+]]:vreg_128 = IMPLICIT_DEF
    ; GFX90A-NEXT: [[COPY1:%[0-9]+]]:vreg_128_align2 = COPY killed [[DEF]]
    ; GFX90A-NEXT: GLOBAL_STORE_DWORDX4 [[COPY]], [[COPY1]], 0, 0, implicit $exec
    %0:vreg_64_align2 = COPY $vgpr0_vgpr1
    %1:vreg_128 = IMPLICIT_DEF
    %2:vreg_128_align2 = COPY killed %1
    GLOBAL_STORE_DWORDX4 %0, %2, 0, 0, implicit $exec
...
